package com.linkage.bss.crm.packagemgr.smo.impl;

import net.sf.json.JSONObject;

import com.linkage.bss.commons.util.JsonUtil;
import com.linkage.bss.crm.packagemgr.bmo.IPackageCheckBMO;
import com.linkage.bss.crm.packagemgr.model.CheckResult;
import com.linkage.bss.crm.packagemgr.model.Package;
import com.linkage.bss.crm.packagemgr.smo.IPackageCheckSMO;
import com.linkage.bss.crm.packagemgr.util.Constant;
import com.linkage.bss.crm.packagemgr.util.ConvertJson;

/**
 * 
 * 包的有效性校验
 * 
 * @author  yh
 * @version  [版本号, 2013-5-10]
 * @see  [相关类/方法]
 * @since  [产品/模块版本]
 */
public class PackageCheckSMOImpl implements IPackageCheckSMO {

	private IPackageCheckBMO packageCheckBMO;

//	private SpecDataDealSMO specDataDealSMO;

	public IPackageCheckBMO getPackageCheckBMO() {
		return packageCheckBMO;
	}

	public void setPackageCheckBMO(IPackageCheckBMO packageCheckBMO) {
		this.packageCheckBMO = packageCheckBMO;
	}

//	public SpecDataDealSMO getSpecDataDealSMO() {
//		return specDataDealSMO;
//	}
//
//	public void setSpecDataDealSMO(SpecDataDealSMO specDataDealSMO) {
//		this.specDataDealSMO = specDataDealSMO;
//	}

	public String checkPackageConfig(Package packageInfo) {
		CheckResult checkResult = packageCheckBMO.checkPackageByObj(packageInfo);
		return ConvertJson.object2json(checkResult);
	}

	public String checkPackageConfig(Long packageId) {
		CheckResult checkResult = packageCheckBMO.checkPackageByPackageId(packageId);
		return ConvertJson.object2json(checkResult);
	}

	public String checkPackageConfigForCRM(Long packageId) {
		Object cacheData = null;//specDataDealSMO.getCacheFromMC(Constant.PACK_CONFIG_CACHE_KEY + packageId);
		CheckResult checkResult = null;
		if (null != cacheData) {
			JSONObject resultStr = JSONObject.fromObject(cacheData);
			System.out.println("cacheData:" + resultStr);
			checkResult = (CheckResult) JsonUtil.getObject(resultStr.toString(), CheckResult.class);
		} else {
			checkResult = packageCheckBMO.checkPackageByPackageId(packageId);
//			specDataDealSMO.putCacheObjToMC(Constant.PACK_CONFIG_CACHE_KEY + packageId, checkResult);
		}
		return ConvertJson.object2json(checkResult);
	}

}
